
/**
 *
 */
package com.serviceprovider.business.module.admin.transaction.controller;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.admin.transaction.services.dao.interfaces.ITransactionDataService;
import com.serviceprovider.business.module.admin.transaction.valueobjects.TransactionCSVHistory;
import com.serviceprovider.business.utility.RequestConstants;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

//~--- JDK imports ------------------------------------------------------------

import java.util.List;

import javax.servlet.http.HttpServletRequest;

/**
 * @author mrduongnv@gmail.com
 *
 */
@Controller
@RequestMapping(value = RequestConstants.TransactionRequests.TRANSACTION_DATA_HISTORY)
public class TransactionDataHistoryController {
    @Autowired
    private ITransactionDataService transactionDataService;

    @ModelAttribute
    @RequestMapping(method = RequestMethod.GET)
    public ModelAndView showHistory(HttpServletRequest request) {
        final String remoteUser = request.getRemoteUser();
        ModelAndView mov        = new ModelAndView(RequestConstants.TransactionRequests.VIEW_TRANSACTION_DATA_HISTORY);

        try {
            final List<TransactionCSVHistory> historyList =
                this.transactionDataService.retrieveTransactionCsvHistoryRecords(remoteUser);

            mov.addObject("historyList", historyList);
        } catch (Exception e) {
            mov.addObject("message", "Error occured when history is displayed.");
        }

        return mov;
    }
}



